﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCSG.Models;
using MVCSG.Context;

namespace MVCSG.Controllers
{
    public class UMArticuloController : Controller
    {
        private BDSG db = new BDSG();

        //
        // GET: /UMArticulo/

        public ActionResult Index()
        {
            return View(db.UMArticuloes.ToList());
        }

        //
        // GET: /UMArticulo/Details/5

        public ActionResult Details(int id = 0)
        {
            UMArticulo umarticulo = db.UMArticuloes.Find(id);
            if (umarticulo == null)
            {
                return HttpNotFound();
            }
            return View(umarticulo);
        }

        //
        // GET: /UMArticulo/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /UMArticulo/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(UMArticulo umarticulo)
        {
            if (ModelState.IsValid)
            {
                db.UMArticuloes.Add(umarticulo);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(umarticulo);
        }

        //
        // GET: /UMArticulo/Edit/5

        public ActionResult Edit(int id = 0)
        {
            UMArticulo umarticulo = db.UMArticuloes.Find(id);
            if (umarticulo == null)
            {
                return HttpNotFound();
            }
            return View(umarticulo);
        }

        //
        // POST: /UMArticulo/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(UMArticulo umarticulo)
        {
            if (ModelState.IsValid)
            {
                db.Entry(umarticulo).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(umarticulo);
        }

        //
        // GET: /UMArticulo/Delete/5

        public ActionResult Delete(int id = 0)
        {
            UMArticulo umarticulo = db.UMArticuloes.Find(id);
            if (umarticulo == null)
            {
                return HttpNotFound();
            }
            return View(umarticulo);
        }

        //
        // POST: /UMArticulo/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            UMArticulo umarticulo = db.UMArticuloes.Find(id);
            db.UMArticuloes.Remove(umarticulo);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}